package com.jieshen.lesson5;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

import static org.jboss.weld.environment.deployment.WeldResourceLoader.getClassLoader;

public class JButtonDemo1 extends JFrame {

    /**
     * 将图片放在JButton上
     */
    public JButtonDemo1() {

        Container container = getContentPane();
        URL url = getClassLoader().getResource("img/2.jpg");
        ImageIcon icon = new ImageIcon(url);

        //把图标放在按钮上
        JButton button = new JButton();
        button.setIcon(icon);
        button.setToolTipText("图片按钮");

        // add
        container.add(button);

        this.setVisible(true);
        setSize(500,300);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new JButtonDemo1();
    }
}
